package org.jsoft.common;

import java.awt.Color;
import java.util.Random;

public class GetRandomColor {

	public static Color getRandColor(int fc, int bc) {
		Random r = new Random();
		if (fc > 255) {
			fc = 255;
		}
		if (bc > 255) {
			bc = 255;
		}
		int red = fc + r.nextInt(bc - fc);
		int green = fc + r.nextInt(bc - fc);
		int blue = fc + r.nextInt(bc - fc);
		return new Color(red, green, blue);
	}

	public static String getRandomColorString(int fc, int bc) {
		Random r = new Random();
		StringBuffer colorString = new StringBuffer();
		if (fc > 255) {
			fc = 255;
		}
		if (bc > 255) {
			bc = 255;
		}
		int red = fc + r.nextInt(bc - fc);
		int green = fc + r.nextInt(bc - fc);
		int blue = fc + r.nextInt(bc - fc);
		colorString.append(Integer.toHexString(red));
		colorString.append(Integer.toHexString(green));
		colorString.append(Integer.toHexString(blue));
		return colorString.toString().toUpperCase();
	}

	public static void main(String[] args) {
		Color color = GetRandomColor.getRandColor(160, 240);
		int x = 123;
		System.out.println(Integer.toHexString(x));
		System.out.println(Integer.toOctalString(x));
		System.out.println(color);

		System.out.println(GetRandomColor.getRandomColorString(40, 240)
				+ "-----");
	}
}
